package com.cloudcc.mobile.view.activity;

import android.app.ProgressDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.cloudcc.cloudframe.bus.EventEngine;
import com.cloudcc.cloudframe.net.ErrorInfo;
import com.cloudcc.cloudframe.net.ResultCallBack;
import com.cloudcc.cloudframe.ui.viewgroup.refresh.PtrDefaultHandler;
import com.cloudcc.cloudframe.ui.viewgroup.refresh.PtrFrameLayout;
import com.cloudcc.cloudframe.ui.viewgroup.refresh.PtrHandler;
import com.cloudcc.cloudframe.ui.viewgroup.refresh.header.DefaultMaterialHeader;
import com.cloudcc.cloudframe.ui.viewgroup.refresh.header.MaterialHeader;
import com.cloudcc.cloudframe.util.DensityUtils;
import com.cloudcc.cloudframe.util.ListUtils;
import com.cloudcc.cloudframe.util.StringUtils;
import com.cloudcc.mobile.AppContext;
import com.cloudcc.mobile.ExtraConstant;
import com.cloudcc.mobile.R;
import com.cloudcc.mobile.ReceiverConstant;
import com.cloudcc.mobile.adapter.MultipleListAdapter;
import com.cloudcc.mobile.bull.*;
import com.cloudcc.mobile.dao.impl.ApprovalEngineImpl;
import com.cloudcc.mobile.dao.impl.BeauInfoShareSet;
import com.cloudcc.mobile.entity.MultipleListmodel;
import com.cloudcc.mobile.entity.beau.BeauInfoEntity;
import com.cloudcc.mobile.entity.beau.BeauInfoEntity.ObjMenu;
import com.cloudcc.mobile.manager.RunTimeManager;
import com.cloudcc.mobile.manager.UrlManager;
import com.cloudcc.mobile.util.PopuWindowUtils;
import com.cloudcc.mobile.util.ViewUtils;
import com.cloudcc.mobile.view.base.BaseActivity;
import com.cloudcc.mobile.view.web.CloudWebViewActivity;
import com.cloudcc.mobile.view.web.WebSyncDefaultProxy;
import com.cloudcc.mobile.view.web.WebSyncDefaultProxy.MonitorParam;
import com.cloudcc.mobile.weight.EmptyLayout;
import com.cloudcc.mobile.widget.CloudCCTitleBar;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;
import com.litesuits.android.log.Log;
import com.mypage.model.GongNiuZiChan;
import com.mypage.utils.AnimViewUtils;
import com.zbar.lib.CaptureActivity;

import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.OnClick;
import butterknife.OnItemClick;

/**
 * 自定义列表内容显示activity
 *
 * @author lhy 2015/11
 */

public class CreateMultipleListActivity extends BaseActivity implements
		PtrHandler, ResultCallBack<MultipleListmodel>,BeauInfoShareSet.BeauinfoToast {
	private ApprovalEngineImpl engine = new ApprovalEngineImpl();
	private MultipleListAdapter mAdapter;
	public static CreateMultipleListActivity install = null;
	private String layoutId;// 布局id
	private String recordId;// 记录id
	private String relatedlistId;// 相关列表id
	private int imagenum;//图片id
	private String id;
	private String prefix;// 对象标识
	private String num;
	private EmptyLayout empty_loading;
	private BeauInfoEntity mBeauInfo;
	private String name;
	String title1;
	private List<ObjMenu> objMenulist = new ArrayList<ObjMenu>();
	private String ACTION = ReceiverConstant.RECEIVE_REFRESH;
	private List<String> list = new ArrayList<String>();
	private String mEns = RunTimeManager.getInstance().getlanguage();
	@Bind(R.id.listview)
	ListView mListView;

	@Bind(R.id.noDataIcom)
	TextView noDataIcom;

	@Bind(R.id.headerbar)
	CloudCCTitleBar headerbar;
	@Bind(R.id.left_image)
	ImageView backbtn;
	@Bind(R.id.right_text)
	TextView rightplus;
	@Bind(R.id.right_image)
	ImageView rightimg;
	@Bind(R.id.load_more_list_view_ptr_frame)
	PtrFrameLayout mRefreshLayout;


	@Bind(R.id.menu_add_icon)
	ImageView menu_add_icon;
	@Bind(R.id.textViewCoustom)
	TextView textViewCoustom;
	@Bind(R.id.toutextview)
	TextView toutextview;



	FrameLayout layoutTop;
//	@Bind(R.id.toastHintContents)
	TextView toastHintContent;
//	@Bind(R.id.imgDeletes)
	ImageView imgDeletess;
	String listTitle;
	private RelativeLayout topLayoutBackg;
	@Override
	public void init(Bundle savedInstanceState) {
		super.init(savedInstanceState);
		layoutTop = (FrameLayout)findViewById(R.id.layoutTop);
		toastHintContent= (TextView) findViewById(R.id.toastHintContent);
		imgDeletess= (ImageView)findViewById(R.id.imgDeletess);
		topLayoutBackg = (RelativeLayout) findViewById(R.id.topLayoutBackg);
		BeauInfoShareSet.getInstance().addBeauinfoToast(this);
		install = this;
		initHeader();
		initAdapter();
		initRefresh();
		initRequestData();

		empty_loading = new EmptyLayout(mContext);
		empty_loading.setLayoutParams(new LayoutParams(
				LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
		ViewUtils.addListViewEmptyView(mContext, mListView, empty_loading);
		empty_loading.empty();
		initReceiver();
	}

	/**
	 * 初始化 header 等参数
	 */
	private void initHeader() {
		Intent intent = getIntent();
		 title1 = intent.getStringExtra("beau.name");
		layoutId = intent.getStringExtra("layoutId");
		recordId = intent.getStringExtra("recordId");
		mEntityNameID = intent.getStringExtra("beau.nameid");
		relatedlistId = intent.getStringExtra("relatedlistId");
		listTitle = intent.getStringExtra("listTitle");
		objMenulist = (List<ObjMenu>) getIntent().getSerializableExtra(
				"objMenulist");
		prefix = intent.getStringExtra("prefix");
		num = intent.getStringExtra("beau.num");
		name = intent.getStringExtra("name");
		headerbar.setTitle(intent.getStringExtra("name"));
		imagenum = intent.getIntExtra("imagenum",0);
		textViewCoustom.setText("全部"+intent.getStringExtra("name"));
		toutextview.setText(num);
		backbtn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				BeauInfoActivity.inatance.finish();
				Intent intent = new Intent(CreateMultipleListActivity.this,BeauInfoActivity.class);
				intent.putExtra("web", returnid);
				intent.putExtra("beau.nameid", mEntityNameID);
				CreateMultipleListActivity.this.finish();
				Log.d("comeback", CreateMultipleListActivity.this.toString()
						+ "详情列表里面的横向布局其中一个退出");
				startActivity(intent);
			}
		});
		if (shouldInterP()) {
			return;
		}
		if (objMenulist.size() == 1) {
			Log.d("istrue", intent.getStringExtra("name") + title1);
			if("en".equals(mEns)){
				headerbar.setRightText("New");
			}else{
				headerbar.setRightText("新建");
			}

		} else if (objMenulist.size() == 0) {
			rightplus.setVisibility(View.GONE);
			rightimg.setVisibility(View.GONE);
		} else {
			headerbar.setRightImageResource(R.drawable.object_add);
		}
		if ((intent.getStringExtra("name").equals("市场活动成员"))
				&& (title1.equals("市场活动"))) {
			headerbar.setRightText("");
		}
		if ((intent.getStringExtra("name").equals("市场活动历史"))) {
			headerbar.setRightText("");
		}
		if(0!=imagenum){
			try {
				Class drawable = R.drawable.class;
				String bgid = "cloudtab" + (imagenum+2) + "_1";
				Field field2 = drawable.getField(bgid);
				int drawableId = field2.getInt(field2.getName());
				menu_add_icon.setImageResource(drawableId);
			} catch (NoSuchFieldException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			}
		}
	}
	public String returnid;
	public String mEntityNameID;
	// 判断是否可以继续运行item的点击事件与新建（某些条件下不可以操作）
	private boolean shouldInterP() {// true 拦截
		if (StringUtils.equals("ocr", prefix)
				|| StringUtils.equals("opt", prefix)) {
			return true;

		}
		return false;
	}
	@OnClick(R.id.imgDeletes)
	public void imgDeletess() {

		layoutTop.setVisibility(View.GONE);
//        setHintToast();
	}
	@OnItemClick(R.id.listview)
	public void itemclick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		Log.d("nagetiaozhuan", prefix + "对象标识" + recordId + relatedlistId);
		Log.d("nagetiaozhuan", objApiNameId + "走了么1");
		// if ((StringUtils.equalsIgnoreCase(prefix,
		// "bbd"))||(StringUtils.equalsIgnoreCase(prefix, "bda"))) {
		if (prefix.equals("bbd")) {
			Intent intent = new Intent(mContext, BeauInfoActivity.class);
			id = list.get(arg2).substring(1, id.length() - 1);
			intent.putExtra("web", id);
//			intent.putExtra(ExtraConstant.EXTRA_URL, UrlManager.getManager()
//					.getTaskOrScheduleDetailUrl(id));
//			MonitorParam monitorParam = new MonitorParam(
//					new String[] { "m=delete" },
//					WebSyncDefaultProxy.STEP_START, new String[] {
//					"taskcondition=today", "m=list&objid=task",
//					"eventcondition=today" }, true,
//					WebSyncDefaultProxy.STEP_START);
//			MonitorParam monitorParam2 = new MonitorParam(
//					new String[] { "m=save" }, WebSyncDefaultProxy.STEP_START,
//					new String[] { "m=query" }, true,
//					WebSyncDefaultProxy.STEP_OVERRIDEURL);
//			MonitorParam monitorParam3 = new MonitorParam(new String[] {
//					"taskcondition=today", "eventcondition=today" },
//					WebSyncDefaultProxy.STEP_START, new String[] {
//					"taskcondition=today", "eventcondition=today" },
//					true, WebSyncDefaultProxy.STEP_START);
//			monitorParam3.isCallBack = false;
//			intent.putExtra(
//					"callback",
//					WebSyncDefaultProxy
//							.creatDefaultProxy(
//									ReceiverConstant.RECEIVE_REFRESH_SCHEDULE)
//							.addMonitorParam(monitorParam)
//							.addMonitorParam(monitorParam2)
//							.addMonitorParam(monitorParam3).addHomeMonitor());

			startActivity(intent);

		} else if (prefix.equals("bda")) {
			Log.d("name", "备注及附件" + "  " + name);
			Intent intent = new Intent(mContext, CloudWebViewActivity.class);
			intent.putExtra("tag", "beizhu");
			intent.putExtra("tags", "cloudcc");
			Log.d("nagetiaozhuan", id + "走了么2	");
			id = list.get(arg2).substring(1, id.length() - 1);
			Log.d("zhuanmenbiaoshi", id + "走了1么");
			intent.putExtra(ExtraConstant.EXTRA_URL, UrlManager.getManager()
					.getTaskOrScheduleDetailUrl1(id));
			Log.d("zhuanmenbiaoshi", id + "走了1么1");
			MonitorParam monitorParam = new MonitorParam(
					new String[] { "m=delete" },
					WebSyncDefaultProxy.STEP_START, new String[] {
					"taskcondition=today", "m=list&objid=task",
					"eventcondition=today" }, true,
					WebSyncDefaultProxy.STEP_START);
			MonitorParam monitorParam2 = new MonitorParam(
					new String[] { "m=save" }, WebSyncDefaultProxy.STEP_START,
					new String[] { "m=query" }, true,
					WebSyncDefaultProxy.STEP_OVERRIDEURL);
			MonitorParam monitorParam3 = new MonitorParam(new String[] {
					"taskcondition=today", "eventcondition=today" },
					WebSyncDefaultProxy.STEP_START, new String[] {
					"taskcondition=today", "eventcondition=today" },
					true, WebSyncDefaultProxy.STEP_START);
			monitorParam3.isCallBack = false;
			intent.putExtra(
					"callback",
					WebSyncDefaultProxy
							.creatDefaultProxy(
									ReceiverConstant.RECEIVE_REFRESH_SCHEDULE)
							.addMonitorParam(monitorParam)
							.addMonitorParam(monitorParam2)
							.addMonitorParam(monitorParam3).addHomeMonitor());

			startActivity(intent);

			// // Uri uri = Uri.parse("www.baidu.com");
			// // Intent it = new Intent(Intent.ACTION_VIEW, uri);
			// // startActivity(it);
		} else {
			BeauInfoActivity.inatance.finish();
			Intent intent = new Intent(mContext, BeauInfoActivity.class);
			intent.putExtra("beau.name",
					TextUtils.isEmpty(objApiNameTilte) ? "" : objApiNameTilte);
			StringBuffer t = mAdapter.getItem(arg2);
			String[] textarr = t.toString().split(";");
			for (int i = 0; i < textarr.length; i++) {
				Log.d("textxxx", "内容" + textarr[i]);
			}
			intent.putExtra("beau.id", textarr[textarr.length - 1]);
			if (shouldInterP()) {
				return;
			}
			if (StringUtils.equalsIgnoreCase(prefix, "001")) {
				intent.putExtra("beau.nameid", "account");
			} else if (StringUtils.equalsIgnoreCase(prefix, "002")) {
				intent.putExtra("beau.nameid", "opportunity");
			} else if (StringUtils.equalsIgnoreCase(prefix, "003")) {
				intent.putExtra("beau.nameid", "contact");
			} else if (StringUtils.equalsIgnoreCase(prefix, "004")) {
				intent.putExtra("beau.nameid", "lead");
			} else if (StringUtils.equalsIgnoreCase(prefix, "bda")) {
				intent.putExtra("beau.nameid", "attachement");
			} else {
				intent.putExtra("beau.nameid",
						TextUtils.isEmpty(objApiNameId) ? "" : objApiNameId);
			}
			Log.d("nagetiaozhuan", objApiNameId + "走了么3	");

			startActivity(intent);
		}
	}

	/**
	 * 初始化刷新
	 */
	protected void initRefresh() {
		mRefreshLayout.setLoadingMinTime(1000);
		mRefreshLayout.setPtrHandler(this);
		final MaterialHeader header = new DefaultMaterialHeader(this);
		int[] colors = getResources().getIntArray(R.array.google_colors);
		header.setColorSchemeColors(colors);
		header.setLayoutParams(new PtrFrameLayout.LayoutParams(-1, -2));
		header.setPadding(0, DensityUtils.dpToPixel(mContext, 10), 0,
				DensityUtils.dpToPixel(mContext, 5));
		header.setPtrFrameLayout(mRefreshLayout);
		mRefreshLayout.setHeaderView(header);
		mRefreshLayout.addPtrUIHandler(header);
		mRefreshLayout.setResistance(5.0f);
	}

	/**
	 * 自动开启刷新请求数据
	 */
	private void initRequestData() {
		mRefreshLayout.postDelayed(new Runnable() {
			@Override
			public void run() {
				mRefreshLayout.autoRefresh(true);
			}
		}, 150);
	}

	private void initAdapter() {
		mAdapter = new MultipleListAdapter(mContext, !shouldInterP());
		mListView.setAdapter(mAdapter);
	}

	/**
	 * 刷新数据
	 */
	private void refreshData() {
		JsonObject jsonObject = new JsonObject();
		jsonObject.addProperty("layoutId", layoutId);
		jsonObject.addProperty("recordId", recordId);
		jsonObject.addProperty("relatedlistId", relatedlistId);
		headerbar.beginProgress();
		returnid = recordId;
		engine.GetMultipleRequest(jsonObject, this);
	}

	@Override
	public int getLayoutId() {
		return R.layout.create_multiple_list_layout;
	}

	@Override
	public boolean checkCanDoRefresh(PtrFrameLayout arg0, View arg1, View arg2) {
		return PtrDefaultHandler.checkContentCanBePulledDown(arg0, mListView,
				arg2);
	}

	@Override
	public void onRefreshBegin(PtrFrameLayout arg0) {
		refreshData();
	}

	@Override
	public void onFailure(ErrorInfo arg0) {
		headerbar.completeProgress();
		Toast.makeText(CreateMultipleListActivity.this, arg0.getErrorMessage(),
				Toast.LENGTH_LONG).show();
	}

	private String objApiNameId = "";
	private String objApiNameTilte = "";
	private boolean isname =false;
	private String isName = "";
	@Override
	public void onSuccess(MultipleListmodel data) {
		headerbar.completeProgress();
		mRefreshLayout.refreshComplete();
		List<StringBuffer> textlist = new ArrayList<StringBuffer>();
        List<StringBuffer> textlistName = new ArrayList<StringBuffer>();
		List<JsonObject> valuelist = data.getRelationData();
		List<JsonObject> lablelist = data.getRelationFieldList();
		objApiNameId = data.relationObjId;
		objApiNameTilte = data.relationObjLabel;
		// 处理写死的
		if (StringUtils.equals("ocr", prefix)) {

			List<JsonObject> lableListTemp = new ArrayList<JsonObject>();

			JsonObject jsonObject = new JsonObject();
			jsonObject.addProperty("name", "rolename");
			jsonObject.addProperty("label", "角色");
			jsonObject.addProperty("type", "S");

			JsonObject jsonObjectTiltle = new JsonObject();
			jsonObjectTiltle.addProperty("name", "contactname");
			jsonObjectTiltle.addProperty("label", "名称");
			jsonObjectTiltle.addProperty("type", "S");
			// 主要
			JsonObject jsonObjectisDe = new JsonObject();
			jsonObjectisDe.addProperty("name", "isdefault");
			jsonObjectisDe.addProperty("label", "主要负责人");
			jsonObjectisDe.addProperty("type", "S");

			lableListTemp.add(jsonObjectisDe);
			lableListTemp.add(jsonObjectTiltle);
			lableListTemp.add(jsonObject);

			lablelist = lableListTemp;
		}

		// lablelist 所有的每条记录的行数
		// valuelist 所有的记录 条数
		if(list.size()>0){
			list.clear();
		}
		for (JsonObject vauleObject : valuelist) {// 确定每条数据有几行
			StringBuffer textobj = new StringBuffer();
            StringBuffer textobjName = new StringBuffer();
			if (lablelist.size() > 0) {
				for (JsonObject jsonObject : lablelist) {
					String title = jsonObject.get("label").getAsString();
					String bridge = "/:";
					String apiKey = jsonObject.get("name").getAsString();
					if("name".equals(apiKey)){
						isname = true;
						mAdapter.setIsname(isname);
					}else{
						isname = false;
//						mAdapter.setIsname(isname,isName);
					}
					String value;
					if (isTypeC(jsonObject.get("type").getAsString())) {// 是不是m
						apiKey += "ccname";
					}
					try {
						boolean jsonNull = vauleObject.get(apiKey).isJsonNull();

						String text;
						if (StringUtils.equals("ocr", prefix)) {
							if (StringUtils.equals("1", vauleObject.get(apiKey)
									.getAsString())) {
								value = "是";
								text = title + bridge + value;
							} else if (StringUtils.equals("0",
									vauleObject.get(apiKey).getAsString())) {
								value = "否";
								text = title + bridge + value;
							}
						}
						//标题特殊处理
						if(!isname) {
							value = jsonNull ? " " : vauleObject.get(apiKey)
									.getAsString();

							text = title + bridge + value;

							textobj.append(text + ";");
						}else{
							isName = jsonNull ? " " : vauleObject.get(apiKey)
									.getAsString();
                            textobjName.append(isName);
						}
					} catch (Exception e) {
					}
				}
			}
			id = vauleObject.get("id").toString();

			list.add(id);
			Log.d("value", " sacfds" + id);

			if (textobj.length() > 0) {
				textobj.append(vauleObject.get("id").getAsString());
				textlist.add(textobj);
			} else {
				try {
					textobj.append(vauleObject.get("name").getAsString() + ";");
					textobj.append(vauleObject.get("id").getAsString());
				} catch (Exception e) {
					e.printStackTrace();
				}
				textlist.add(textobj);
			}
			if(textobjName.length() > 0){
                textlistName.add(textobjName);
            }

		}
		if (textlist.size() < 1) {
			empty_loading.empty();
			toutextview.setText("0");
			noDataIcom.setVisibility(View.VISIBLE);
		}else {
			toutextview.setText(textlist.size()+"");
			noDataIcom.setVisibility(View.GONE);
		}
		mAdapter.setname(textlistName);
		mAdapter.setId(imagenum);
		mAdapter.changeData(textlist);
	}
	private int drawableId;

	@Override
	public void showToast(String str) {
		if (!"".equals(str) && "保存成功".equals(str)) {
			topLayoutBackg.setBackground(getResources().getDrawable(R.drawable.toast_hint_beau));
			topLayoutBackg.setVisibility(View.GONE);
			toastHintContent.setText(getString(R.string.save_success));
			layoutTop.setVisibility(View.VISIBLE);
			new AnimViewUtils().appearToast(topLayoutBackg);
        }
	}

	public class MyItem {
		public List<SubItem> mlist;

		public class SubItem {
			public String title;
			public String value;
		}
	}

	private boolean isTypeC(String type) {
		for (String iterable_element : types) {
			if (StringUtils.equalsIgnoreCase(iterable_element, type)) {
				return true;
			}
		}
		return false;
	}

	private final String[] types = new String[] { "Y", "M", "R" };

	@OnClick(R.id.right_text)
	public void clicktext() {
		Log.d("---title1",title1+"--");
		Log.d("---recordId",recordId+"--");
		Log.d("---listTitle",listTitle+"--");
		if("门店".equals(name)){
			Intent intent=new Intent(mContext, GongniuAddShopActivity.class);
			if("经销商".equals(title1)){
				intent.putExtra("id",recordId);
				intent.putExtra("title",title1);
				intent.putExtra("name",listTitle);
			}

			startActivity(intent);
		}else if("工作记录".equals(name)){
			Intent intent=new Intent(mContext,com.cloudcc.mobile.bull.BullNewJobActivity.class);
			if("经销商".equals(title1)||"门店".equals(title1)){
				intent.putExtra("id",recordId);
				intent.putExtra("title",title1);
				intent.putExtra("name",listTitle);
			}
			startActivity(intent);
		}else if("营销资产管理记录".equals(name)){
			/*Intent intent=new Intent(mContext, CaptureActivity.class);
			intent.putExtra("tag","gongniu");*/
			Log.d("---gongniu",recordId);
			Log.d("---title",title1);
			Log.d("---name",listTitle);
			//startActivity(intent);
			requestNumNo(listTitle);
		}else {
			ObjMenu objMenu = objMenulist.get(0);
			Intent intent = new Intent(mContext, CloudWebViewActivity.class);
			intent.putExtra(
					ExtraConstant.EXTRA_URL,
					UrlManager.getManager().addReturnUrl(
							UrlManager.getManager().getUrlByRoot(
									objMenu.relationUrl)));
			Log.d("---URL", UrlManager.getManager().addReturnUrl(
					UrlManager.getManager().getUrlByRoot(
							objMenu.relationUrl)) + "---");
			MonitorParam monitorParam = new MonitorParam(new String[]{"m=save",
					"m=query", "type=remark"}, WebSyncDefaultProxy.STEP_START,
					new String[]{"/WeiXin_index.action", "m=query"}, true,
					WebSyncDefaultProxy.STEP_OVERRIDEURL);
			intent.putExtra(
					"callback",
					WebSyncDefaultProxy.creatDefaultProxy(ACTION)
							.addMonitorParam(monitorParam).addHomeMonitor());
			intent.putExtra("from", "beauinfo");
			startActivity(intent);
		}
	}

	private PopupWindow mRightMenu;

	@OnClick(R.id.right_image)
	public void clicknew() {
		showRightPopu();
	}

	private void showRightPopu() {
		if (objMenulist == null || ListUtils.isEmpty(objMenulist)) {
			return;
		}
		PopuWindowUtils.dissmiss(mRightMenu);
		View contentView = (View) View.inflate(mContext,
				R.layout.layout_popu_container, null);
		LinearLayout subContainer = (LinearLayout) contentView
				.findViewById(R.id.pop_holder);
		final int excNum = objMenulist.size() > 3 ? 3 : objMenulist.size();
		int popuHeight = 0;
		for (int i = 0; i < objMenulist.size(); i++) {
			View containerView = View.inflate(mContext,
					R.layout.layout_pop_item, null);
			ImageView ivLogo = (ImageView) containerView
					.findViewById(R.id.pop_item_image);
			ivLogo.setVisibility(View.VISIBLE);
			TextView tvTitle = (TextView) containerView
					.findViewById(R.id.pop_item_text);
			ImageView LIne = (ImageView) containerView
					.findViewById(R.id.item_line);
			if (i==objMenulist.size()-1){
				LIne.setVisibility(View.GONE);
			}
			popuHeight += ViewUtils.getViewMeasuredHeight(containerView);
			if (i > 3 && i != objMenulist.size() + 2) {
				containerView.setVisibility(View.GONE);
			}
			ObjMenu objMenu = objMenulist.get(i);
			if ("新建备注".equals(objMenu.relationName)||objMenu.relationName.contains("Note")){
				ivLogo.setImageResource(R.drawable.newone);
			}else if ("添加附件".equals(objMenu.relationName)||objMenu.relationName.contains("Add")){
				ivLogo.setImageResource(R.drawable.newtwo);
			}
			tvTitle.setText(objMenu.relationName);
			tvTitle.setTextColor(Color.BLACK);
			Log.d("objmenu", objMenu.relationName + "新建？");
			containerView.setOnClickListener(new MyMenuClick(i));
			subContainer.addView(containerView);
		}
//		AppContext.screenW / 2
		mRightMenu = new PopupWindow(contentView, LayoutParams.WRAP_CONTENT,
				LayoutParams.WRAP_CONTENT);
		mRightMenu.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
		mRightMenu.setFocusable(true);
        if ("en".equals(mEns)){
            mRightMenu.showAsDropDown(rightimg,-390,0);
        }else{
//            mRightMenu.showAsDropDown(rightimg,-313,0);
			mRightMenu.showAsDropDown(rightimg,-305,0);
        }


	}

	private class MyMenuClick implements OnClickListener {

		private int mPosition;

		public MyMenuClick(int position) {
			super();
			this.mPosition = position;
		}

		@Override
		public void onClick(View v) {
			if (mPosition < objMenulist.size()) {
				PopuWindowUtils.dissmiss(mRightMenu);
				ObjMenu objMenu = objMenulist.get(mPosition);
				Intent intent = new Intent(mContext, CloudWebViewActivity.class);
				intent.putExtra(
						ExtraConstant.EXTRA_URL,
						UrlManager.getManager().addReturnUrl(
								UrlManager.getManager().getUrlByRoot(
										objMenu.relationUrl)));
				Log.d("objmenuclick", objMenu.relationUrl + "路徑");
				MonitorParam monitorParam = new MonitorParam(new String[] {
						"m=save", "m=query", "type=remark" },
						WebSyncDefaultProxy.STEP_START, new String[] {
						"/WeiXin_index.action", "m=query" }, true,
						WebSyncDefaultProxy.STEP_OVERRIDEURL);
				intent.putExtra("callback", WebSyncDefaultProxy
						.creatDefaultProxy(ACTION)
						.addMonitorParam(monitorParam).addHomeMonitor());
				intent.putExtra("from","beauinfo");
				startActivity(intent);
			}
		}
	};

	private SyncReceiver mSyncReceiver;

	private void initReceiver() {
		mSyncReceiver = new SyncReceiver();
		IntentFilter filter = new IntentFilter();
		filter.addAction(ACTION);
		mContext.registerReceiver(mSyncReceiver, filter);
	}

	private class SyncReceiver extends BroadcastReceiver {
		@Override
		public void onReceive(Context context, Intent intent) {
			initRequestData();
		}
	}

	@Override
	public void onDestroy() {
		if (mSyncReceiver != null) {
			mContext.unregisterReceiver(mSyncReceiver);
		}
		EventEngine.uregister(this);
		super.onDestroy();
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		initRequestData();
        String Unames = RunTimeManager.getInstance().getUserName();
        if ("保存成功".equals(Unames)) {
            topLayoutBackg.setVisibility(View.GONE);
			toastHintContent.setText(getString(R.string.save_success));
            layoutTop.setVisibility(View.VISIBLE);
            new AnimViewUtils().appearToast(topLayoutBackg);
        }
	}






	/*
	* 资产巡检
	* */

	public String ssmendian;
	public String tfdz;
	public String name1;
	public String zcmc;
	public String zclx;
	ProgressDialog dialog2;
	public void requestNumNo(final String name) {
		dialog2=new ProgressDialog(this);
		dialog2.show();
		HttpUtils utils = new HttpUtils();
		RequestParams params = new RequestParams();
		params.addBodyParameter("binding", RunTimeManager.getInstance()
				.getServerBinding());
		params.addBodyParameter("serviceName", "cquery");
		params.addBodyParameter("objectApiName", "yxzc");
		params.addBodyParameter("expressions", "name=" + "'" + name + "'");
		Log.d("列表值url-------------------------", UrlManager.getInterfaceUrl()
				+ "?binding=" + RunTimeManager.getInstance().getServerBinding()
				+ "&serviceName=getLookupValue"
				+ "&objectId=2016360343BD7B2SQ2PO" + "&pageSize=1"
				+ "&keyword=");
		utils.send(HttpRequest.HttpMethod.POST, UrlManager.getInterfaceUrl(), params,
				new RequestCallBack<String>() {
					@Override
					public void onFailure(HttpException arg0, String arg1) {
						Log.d("列表值接口失败-------------------------", arg1);
						Toast.makeText(CreateMultipleListActivity.this, "资产出错", Toast.LENGTH_SHORT).show();
						dialog2.dismiss();
					}

					@Override
					public void onSuccess(ResponseInfo<String> arg0) {
						Log.d("列表值接口成功-------------------------", arg0.result);
						Gson gson = new Gson();
						GongNiuZiChan mData = gson.fromJson(arg0.result.toString(),
								GongNiuZiChan.class);
						if (mData.data.size() <= 0) {
							Toast.makeText(CreateMultipleListActivity.this, "该资产编码不存在", Toast.LENGTH_SHORT).show();
							//finish();
						} else {
							mData.data.get(0);
							ssmendian = mData.data.get(0).ssmendianccname;
							tfdz = mData.data.get(0).tfdz;
							name1 = mData.data.get(0).name;
							zcmc = mData.data.get(0).zcmc;
							zclx = mData.data.get(0).zclx;

							requestNum(name,mData);
						}
					}
				});
	}

	public void requestNum(String name, final GongNiuZiChan mDatax) {

		HttpUtils utils = new HttpUtils();
		RequestParams params = new RequestParams();
		params.addBodyParameter("binding", RunTimeManager.getInstance()
				.getServerBinding());
		params.addBodyParameter("serviceName", "cqueryWithRoleRight");
		params.addBodyParameter("objectApiName", "yxzc");
		params.addBodyParameter("expressions", "name=" + "'" + name + "'");
		Log.d("列表值url-------------------------", UrlManager.getInterfaceUrl()
				+ "?binding=" + RunTimeManager.getInstance().getServerBinding()
				+ "&serviceName=getLookupValue"
				+ "&objectId=2016360343BD7B2SQ2PO" + "&pageSize=1"
				+ "&keyword=");
		Log.d("request", UrlManager.getInterfaceUrl() + "serviceName=cqueryWithRoleRight" + "objectApiName=yxzc" + "expressions=name="+"'"+name+"'" + "binding=" + RunTimeManager.getInstance()
				.getServerBinding());
		utils.send(HttpRequest.HttpMethod.POST, UrlManager.getInterfaceUrl(), params,
				new RequestCallBack<String>() {
					@Override
					public void onFailure(HttpException arg0, String arg1) {
						Log.d("列表值接口失败-------------------------", arg1);
						dialog2.dismiss();
					}
					@Override
					public void onSuccess(ResponseInfo<String> arg0) {
						dialog2.dismiss();
						Log.d("列表值接口成功-------------------------", arg0.result);
						Gson gson = new Gson();
						GongNiuZiChan mData = gson.fromJson(arg0.result.toString(),
								GongNiuZiChan.class);
						if (mData.data.size() <= 0) {
							Toast.makeText(CreateMultipleListActivity.this, "该资产无需巡检", Toast.LENGTH_SHORT).show();
							finish();
						} else {
							if (null == mData.data.get(0).ssjxsccname || "".equals(mData.data.get(0).ssjxsccname)) {
								Toast.makeText(CreateMultipleListActivity.this, "该资产无需巡检", Toast.LENGTH_SHORT).show();
								finish();
							} else {
								Intent intent = new Intent(CreateMultipleListActivity.this, com.cloudcc.mobile.bull.BullXunjianActivity.class);
								Bundle bundle = new Bundle();
								bundle.putSerializable("gongniudata", (Serializable) mDatax.data.get(0));
								intent.putExtras(bundle);
//                                intent.putExtra("ssmendian",ssmendian);
//                                intent.putExtra("tfdz",tfdz);
//                                intent.putExtra("name1",name1);
//                                intent.putExtra("zcmc",zcmc);
//                                intent.putExtra("zclx",zclx);
								intent.putExtra("ssjxs",mData.data.get(0).ssjxsccname);
								startActivity(intent);
								finish();
							}
						}
					}
				});
	}

}
